package com.zenithmind.news.controller;

import com.zenithmind.common.context.UserContext;
import com.zenithmind.common.result.Result;
import com.zenithmind.news.service.NewsInteractionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 新闻交互控制器 - 遵循单一职责原则
 * 专门负责用户与新闻的交互操作（点赞、收藏、分享等）
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Tag(name = "新闻交互", description = "新闻交互相关接口")
@RestController
@RequestMapping("/api/zenithMind/v1/news/interaction")
@RequiredArgsConstructor
public class NewsInteractionController {

    private final NewsInteractionService newsInteractionService;

    @Operation(summary = "点赞新闻", description = "点赞指定新闻")
    @PostMapping("/{id}/like")
    public Result<Boolean> likeNews(@Parameter(description = "新闻ID") @PathVariable String id) {
        String userId = UserContext.getUserId();
        Boolean result = newsInteractionService.likeNews(id, userId);
        return Result.success(result);
    }

    @Operation(summary = "取消点赞新闻", description = "取消点赞指定新闻")
    @DeleteMapping("/{id}/like")
    public Result<Boolean> unlikeNews(@Parameter(description = "新闻ID") @PathVariable String id) {
        String userId = UserContext.getUserId();
        Boolean result = newsInteractionService.unlikeNews(id, userId);
        return Result.success(result);
    }

    @Operation(summary = "收藏新闻", description = "收藏指定新闻")
    @PostMapping("/{id}/favorite")
    public Result<Boolean> favoriteNews(@Parameter(description = "新闻ID") @PathVariable String id) {
        String userId = UserContext.getUserId();
        Boolean result = newsInteractionService.favoriteNews(id, userId);
        return Result.success(result);
    }

    @Operation(summary = "取消收藏新闻", description = "取消收藏指定新闻")
    @DeleteMapping("/{id}/favorite")
    public Result<Boolean> unfavoriteNews(@Parameter(description = "新闻ID") @PathVariable String id) {
        String userId = UserContext.getUserId();
        Boolean result = newsInteractionService.unfavoriteNews(id, userId);
        return Result.success(result);
    }

    @Operation(summary = "分享新闻", description = "分享指定新闻")
    @PostMapping("/{id}/share")
    public Result<Boolean> shareNews(
            @Parameter(description = "新闻ID") @PathVariable String id,
            @Parameter(description = "分享平台") @RequestParam String platform) {
        String userId = UserContext.getUserId();
        Boolean result = newsInteractionService.shareNews(id, userId, platform);
        return Result.success(result);
    }
}
